package com.probiz.estoresa.other.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.other.Tag;
import com.probiz.estore.core.controller.GenericStoreAdminController;
import com.probiz.estore.other.service.TagManager;
import com.probiz.estore.webapp.util.RequestUtil;

public class TagSelectorController extends GenericStoreAdminController<Tag> {
    private TagManager tagManager = null;

    public void setTagManager(TagManager inMgr) {
        this.tagManager = inMgr;
    }

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.GenericController#getEntityName(java.lang.Object)
	 */
	@Override
	protected String getEntityName(Tag entity) {
		return entity.getTagName();
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.BaseController#initController()
	 */
	@Override
	protected void initController() throws Exception {
		mgr = tagManager;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.GenericController#onSave(javax.servlet.http.HttpServletRequest,
	 *      java.lang.Object, org.springframework.validation.BindException)
	 */
	@Override
	protected void preSave(HttpServletRequest request, Tag entity, BindException errors) {
	}
	
	public ModelAndView refreshTagChooser(HttpServletRequest request,	HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("other/tagSelectorForChooser");
		List<Tag> tagList = tagManager.listByProperty("module", Short.valueOf(RequestUtil.getParameterNullSafe(request, "module")));
		mv.addObject("tagList",tagList);
		mv.addObject("selectorId",RequestUtil.getParameterNullSafe(request, "selectorId"));
		return mv;
	}

}
